package com.example.shop_2212.preorder

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.GetPreOrderEntityResult
import com.example.base.entity.OrderEntityResult
import com.example.base.entity.ParamOrder
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class PreOrderViewModel:BaseViewModel() {
    //返回值--获取预下单
    val getSuccess = MutableLiveData<GetPreOrderEntityResult>()
    val getFail = MutableLiveData<String>()
    fun getPreOrder(preOrderNo:String){
        viewModelScope.launch {
            try {
                getSuccess.value = apiServer.getPreOrder(preOrderNo)
            }catch (e:Exception){
                getFail.value = e.message
            }
        }
    }
    //返回值--创建订单
    val orderSuccess = MutableLiveData<OrderEntityResult>()
    val orderFail = MutableLiveData<String>()
    fun order(body: ParamOrder){
        viewModelScope.launch {
            try {
                orderSuccess.value = apiServer.order(body)
            }catch (e:Exception){
                orderFail.value = e.message
            }
        }
    }
}